/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qlvbdq.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import qlvbdq.jdbc.SQLServerConnect;
import qlvbdq.objects.ObUser;

/**
 *
 * @author tuan
 */
public class MUser {
    SQLServerConnect connect;
    
    public MUser(){
    }
    
    public ArrayList<ObUser> GetAllUserFromDatabase() throws SQLException {
        ArrayList<ObUser> listUser = new ArrayList<ObUser>();
        ResultSet result = connect.getDataFromStore("GetAllDataOfUser", null);
        ObUser user = new ObUser();
        while (result.next()) {
            user.setUserName(result.getString("USERNAME"));
            user.setPassword(result.getString("PASSWORDS"));
            user.setLoaiNguoiDung(result.getString("LOAINGUOIDUNG"));
            listUser.add(user);
        }
        return listUser;
    }
    
    //update 1 user
    public int updateUserToDatabase(ObUser user) {
        Object[] objs = { user.getUserName(), user.getPassword(), user.getLoaiNguoiDung()};
        return connect.updateDataToDatabase("UpdateUserToDatabase(?, ?, ?)", objs);
    }
    
    //delete 1 user
    public int deleteUserToDatabase(ObUser user) {
        Object[] objs = { user.getUserName() };
        return connect.updateDataToDatabase("DeleteUserToDatabase(?)", objs);
    }
    
    public int InsertUserToDatabase(ObUser user) {
        Object[] objs = { user.getUserName(), user.getPassword(), user.getLoaiNguoiDung()};
        return connect.updateDataToDatabase("InsertUserToDatabase(?, ?, ?)", objs);
    }
    
}
